<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.ort">
<head>
	<meta charset="UTF-8">
	<title>系统人员</title>
	<script th:src="@{/layui/layui.js}" type="text/javascript"></script>
	<link th:href="@{/layui/css/layui.css}" rel="stylesheet" />
	<style>
		.layui-elem-quote{
			border-left: 5px solid #1e9fff;
		}
	</style>
</head>
<body>

<div class="layui-panel" style="padding: 8px;">
	<blockquote class="layui-elem-quote layui-border-blue">定时任务配置</blockquote>
	<div>
		<table id="quartzTable" lay-filter="quartzTable"></table>
	</div>
</div>
<script id="tool" type="text/html">
	<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="one">执行一次</a>
	<a class="layui-btn layui-btn-xs" lay-event="start">启动</a>
	<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="stop">暂停</a>
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
</script>
<script id="tableBar" type="text/html">
	<a class="layui-btn layui-btn-normal layui-btn-md" lay-event="add">
		<i class="layui-icon layui-icon-add-1"></i>
		新增任务
	</a>
</script>
<script id="swicthState" type="text/html">
	<input type="checkbox" name="state" value="{{d.state}}"
		   lay-skin="switch" lay-text="运行中|未运行" lay-filter="checkState" {{d.state=="ACQUIRED"?"checked":""}} />
</script>
<script id="corn" type="text/html">
	<div style="float: left;">
		{{d.corn}}
	</div>
	<div style="float: right;">
		<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="createCorn">修改corn表达式</a>
	</div>
</script>
<script>

	var $;
	layui.use(['table','form','layer'],function(){
		var table = layui.table,
				form = layui.form,
				layer = layui.layer;
		$ = layui.$;
		//加载表格
		table.render({
			elem:'#quartzTable',
			height:'full-105',
			page:{
				theme:'#1e9fff'
			},
			toolbar:'#tableBar',
			url:'/system/sc/find',
			cols:[
				[
					{type:'numbers',fixed:'left'},
					{type:'checkbox',fixed:'left'},
					{field:'jobName',title:'任务名称',width:120},
					{field:'jobGroup',title:'任务组名',width:120},
					{field:'className',title:'类名',width:280},
					{field:'corn',title:'corn表达式',width:280,templet:'#corn'},
					{field:'state',title:'任务状态',width:120,templet:'#swicthState'},
					{field:'triggerName',title:'触发器名称',width:180},
					{field:'triggerGroup',title:'触发器组名',width:180},
					{field:'timeZone',title:'创建时间',width:180},
					{fixed:'right',title:'操作',width:300,align:'center',toolbar:'#tool'},
				]
			]
		})

		var active = {
			openQuartz:function (title,id,did) {
				var b =false;
				top.layer.open({
					type:2,
					content:'/page/system/'+did+'Quartz'+(id=""?"":"/"+id),
					title:title,
					area:['700px','500px'],
					btn:['确定保存','取消关闭'],
					btn1:function (i,o) {
						//active.saveQuartz(i,'addData');
						b = true;
						o.find('iframe')[0].contentWindow.submitBtn();
					},
					end:function (){
						if(b) layui.table.reload('quartzTable');
					}
				})
			},
			saveQuartz:function (i,formId) {
				$('#submitBtn').click();
				alert();
			}
		}

		table.on('toolbar(quartzTable)',function (obj) {
			var event = obj.event;
			if('add' == event){
				active.openQuartz('新增定时任务',"",'add');
			}
		});
		table.on('tool(quartzTable)',function (obj) {
			var event = obj.event;
			var data = obj.data;
			if('createCorn' == event){
				top.layer.open({
					title:'选择corn表达式',
					type:2,
					content:'/page/system/editCorn',
					area:['900px','650px'],
					offset:'c',
					id:'cronIframe',
					btn:['确定','取消'],
					btn1:function(i,o){
						var value = o.find('iframe')[0].contentWindow.getValue();
						//$("#cron").val(value);
						data.corn = value;
						$.ajax({
							type:'post',
							url:'/system/sc/update',
							data:data,
							dataType:'json',
							success:function(result){
								layer.msg(result.msg);
								if(result.is){
									layer.close(i);//关闭父页面窗口
								}
							}
						})
					},
					end:function(){
						layui.table.reload('quartzTable');
					}
				});
			}
			else if("one" == event){
				$.ajax({
					type:'post',
					url:'/system/sc/runOne',
					data:data,
					dataType:'json',
					success:function (res) {
						layer.msg(res.msg);
					}
				})
			}else if("delete" == event){

			}
		});


	});
</script>
</body>
</html>
